package com.youlai.system.controller;

import com.youlai.system.common.base.BaseQuery;
import com.youlai.system.common.result.Result;
import com.youlai.system.model.query.UserBusinessQuery;
import com.youlai.system.model.vo.*;
import com.youlai.system.security.util.SecurityUtils;
import com.youlai.system.service.DashBoardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页控制器
 */
@Tag(name = "17.首页接口")
@RestController
@RequestMapping("/api/v1/dashboards")
@RequiredArgsConstructor
public class DashBoardController {

    private final DashBoardService dashBoardService;

    @Operation(summary = "获取首页数量统计")
    @GetMapping("/loadAllCountData")
    public Result<DashBoardCountVO> loadAllCountData() {
        BaseQuery baseQuery = new BaseQuery();
        if (SecurityUtils.isStudent()) {
            baseQuery.setLoginUserId(SecurityUtils.getUserId());
        }
        DashBoardCountVO dashBoardCountVO = dashBoardService.loadAllCountData(baseQuery);
        return Result.success(dashBoardCountVO);
    }

    @Operation(summary = "获取首页问题分类柱状图数量统计")
    @GetMapping("/loadQuestionCountData")
    public Result<List<QuestionScoreCountVO>> loadQuestionCountData() {
        BaseQuery baseQuery = new BaseQuery();
        if (SecurityUtils.isStudent()) {
            baseQuery.setLoginUserId(SecurityUtils.getUserId());
        }
        List<QuestionScoreCountVO> questionScoreCountVOList = dashBoardService.loadQuestionCountData(baseQuery);
        return Result.success(questionScoreCountVOList);
    }

    @Operation(summary = "获取首页培训地点雷达图数量统计")
    @GetMapping("/loadLocationCountData")
    public Result<List<LocationScoreCountVO>> loadLocationCountData() {
        BaseQuery baseQuery = new BaseQuery();
        if (SecurityUtils.isStudent()) {
            baseQuery.setLoginUserId(SecurityUtils.getUserId());
        }
        List<LocationScoreCountVO> locationScoreCountVOList = dashBoardService.loadLocationCountData(baseQuery);
        return Result.success(locationScoreCountVOList);
    }

    @Operation(summary = "获取首页整改措施雷达图数量统计")
    @GetMapping("/loadMeasureCountData")
    public Result<List<MeasureScoreCountVO>> loadMeasureCountData() {
        BaseQuery baseQuery = new BaseQuery();
        if (SecurityUtils.isStudent()) {
            baseQuery.setLoginUserId(SecurityUtils.getUserId());
        }
        List<MeasureScoreCountVO> measureScoreCountVOList = dashBoardService.loadMeasureCountData(baseQuery);
        return Result.success(measureScoreCountVOList);
    }

    @Operation(summary = "获取首页故障科目折柱混合数量统计")
    @GetMapping("/loadCourseCountData")
    public Result<List<CourseScoreCountVO>> loadCourseCountData() {
        BaseQuery baseQuery = new BaseQuery();
        if (SecurityUtils.isStudent()) {
            baseQuery.setLoginUserId(SecurityUtils.getUserId());
        }
        List<CourseScoreCountVO> courseScoreCountVOList = dashBoardService.loadCourseCountData(baseQuery);
        return Result.success(courseScoreCountVOList);
    }

    @Operation(summary = "获取首页部门等级折柱混合数量统计")
    @GetMapping("/loadDeptDegreeCountData")
    public Result<List<DeptDegreeCountVO>> loadDeptDegreeCountData() {
        List<DeptDegreeCountVO> deptDegreeCountVOList = dashBoardService.loadDeptDegreeCountData();
        return Result.success(deptDegreeCountVOList);
    }

    @Operation(summary = "获取首页等级饼图数量统计")
    @GetMapping("/loadDegreeCountData")
    public Result<List<DegreeCountVO>> loadDegreeCountData() {
        BaseQuery baseQuery = new BaseQuery();
        if (SecurityUtils.isStudent()) {
            baseQuery.setLoginUserId(SecurityUtils.getUserId());
        }
        List<DegreeCountVO> courseScoreCountVOList = dashBoardService.loadDegreeCountData(baseQuery);
        return Result.success(courseScoreCountVOList);
    }

    @Operation(summary = "获取个人信息报告单")
    @GetMapping("/getUserBusinessCard")
    public Result<UserBusinessCard> getUserBusinessCard(UserBusinessQuery query) {
        UserBusinessCard userBusinessCard = dashBoardService.getUserBusinessCard(query);
        return Result.success(userBusinessCard);
    }
}
